# -*- coding: utf-8 -*-
# @File      :python数据库操作
# @Author    :liaogan
# @Datetime  :2022/12/1 16:55

import pymysql


#创建数据库连接对象：host默认一般是localhost，用户名和密码是自己创建数据库时所设定的，database为数据库名称

db = pymysql.connect(host='10.200.8.16', port=3306, user='eshop', passwd='eshop2020',db='v2_pagoda_overall', charset='utf8')

#创建游标
cursor=db.cursor()


"""查询"""
#执行sql
data=cursor.execute('select* from article where id>=460')
print(data)
# #查询一条数据
# print(cursor.fetchone())
#查询多条语句
for one in cursor.fetchall():
    print(one)
# #查询数据行数
# num=cursor.rowcount
# print(num)



# """插入SQL语句"""
# # 执行SQL语句
# sql="INSERT INTO article(`id`, `authorID`, `articleCategoryID`, `title`, `enableComment`, `enableBest`, `lifeStatus`, `releaseStatus`, `sort`, `releaseTime`, `createTime`, `lastUpdate`, `squarePicture`, `squarePicEnable`) " \
#                     "VALUES (465, 130, 179, 'test20221202', 'N', 'N', 'N', 'Y', NULL, '2021-12-03 11:01:39', '2021-12-03 11:01:32', '2021-12-03 11:01:39', '/group1/M00/22/14/CsgEDmGpiHCAdKtEAAKJ_puEye0659.jpg?width=750&height=750', 'Y')"
# try:
#
#     #执行sql语句
#     cursor.execute(sql)
#     db.commit()
#     print('插入数据成功')
# except:
#     # 如果发生错误则回滚
#     db.rollback()
#     print("数据插入失败")



# """更新的SQL语句（不唯一)"""
# sql = "update article SET title='测试2022' whereid=460"
# try:
#    # 执行SQL语句
#    cursor.execute(sql)
#    # 提交到数据库执行
#    db.commit()
#    print("数据更新成功")
# except:
#    # 发生错误时回滚
#    db.rollback()
#    print('数据更新失败')



# """删除sql语句"""
# sql="delete from article where id='465'"
# try:
#     cursor.execute(sql)
#     db.commit()
#     print('数据删除成功')
# except:
#     #发生错误回滚
#     db.rollback()
#     print('数据删除失败')


